import React, { Component } from 'react';

// export default class App extends Component {
//   state={
//     file:'',
//   };
//   componentDidMount(){
//     document.getElementById("file").addEventListener("change",function(e){
//       console.log(e.target.files);
//     })
//   }
//   render() {
//     return (
//       <div>
//         <input type="file" name="" id="file"/>
//       </div>
//     );
//   }
// }

// import React, { Component } from 'react';

export default class App extends Component {
  constructor(props){
    super(props);
    this.fileRef = React.createRef();
  }
  state={
    file:'',
  };
  handleClick=() => {
    console.log(this.fileRef.current);
  }
  render() {
    return (
      <div>
        <input type="file" name="" id="" ref={this.fileRef}/>
        <button onClick = {this.handleClick}>获取filedom元素</button>
      </div>
    );
  }
}